package com.itmuch.contentcenter.sentineltest;

import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlCleaner;
import java.util.Arrays;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Component;


/**
 * @author caiqian
 * @date 2021/5/8 16:29
 */
@Component
public class MyUrlCleaner implements UrlCleaner {

  @Override
  public String clean(String s) {
    String[] split = s.split("/");

    return Arrays.stream(split).map(str -> {
      if (NumberUtils.isNumber(str)) {
        return "{number}";
      }
      return str;
    })
    .reduce((a, b) -> a + "/" + b)
    .orElse("");
  }
}
